var $uploadTodoList = $('#uploadTodoList');

$(function() {
	// 材料上传列表
	$uploadTodoList.jqGrid({
		url:PATH_PREFIX + 'toUploadListPage.do',    
		datatype: "json",
		colNames:["id","管理人", "待办类型","待办日期","产品简称","产品代码","status", "状态", "操作"],        
		colModel:[  { name: 'id', index: 'id', key: true, hidden:true },       
		            { name: 'companyName', index: 'companyName', width: 30, resizable: true, sortable: false, hidden:true },
		            { name: 'todoTypeName', index: 'todoTypeName', width: 30, resizable: true, sortable: false },
		            { name: 'todoDate', index: 'todoDate', width: 25, resizable: true, sortable: false },
		            { name: 'prjSname', index: 'prjSname', width: 25, resizable: true, sortable: false },
		            { name: 'outerId', index: 'outerId', width: 25, resizable: true, sortable: false },
		            { name: 'status', index: 'status', hidden:true },
		            { name: 'statusNm', index: 'statusNm', width: 25, resizable: true, sortable: false },
		            { name: 'option', index: 'option', width: 40, resizable: true, sortable: false }
				  ],
		postData: {
			'sp[serviceType]': toUploadListType,
			'sp[statusType]': 'toUpload'
		},
		rowNum: 10,
        rowList: [10, 20, 30, 50],
        rownumbers: true,
        rownumWidth: 50,
        prmNames: { search: "search", page: "pageNo", rows: "limit" },
        height: 'auto',
        width: false,
        autowidth:true,
        editurl: '',
        viewrecords: true,
        cellEdit: false,
        shrinkToFit: true,
        grouping: false,
        jsonReader: {
            root: "items", //结果集
            records: "total", //总记录数 
            total: "pageCount", //总页数
            page: "pageNo", //当前页 
            repeatitems: false // (4) 
        },  
		multiselect:false,
		pager: "#uploadTodoListPage",
		viewrecords: true,
		hidegrid: false, 
		gridComplete: function(){
			var ids = $uploadTodoList.jqGrid('getDataIDs');
			for(var i = 0;i < ids.length;i++){
				var rowId = ids[i];
				var rowData = $uploadTodoList.jqGrid('getRowData', rowId);
				
				var params = {
					'fileUpload' : 'fileUploadTemp',
					'noFileUpload' : 'noFileUploadTemp'
				};
				var permissionButton = Permission_Button.configPermissionButton(params);
				if (rowData.status == 'I' || rowData.status == 'R') {
					permissionButton.fileUpload   = Permission_Button.clickPermissionButton('fileUploadTemp',"TODO_OUTPUT.fileUpload('" + rowId + "');");
					permissionButton.noFileUpload   = Permission_Button.clickPermissionButton('noFileUploadTemp',"TODO_OUTPUT.noFileUpload('" + rowId + "');");
				}
				
				$uploadTodoList.jqGrid('setRowData', ids[i], { option: Permission_Button.linkAllBtn(permissionButton)});
			}
		}
	});
	$uploadTodoList.navGrid('#uploadTodoListPage',{edit:false,add:false,del:false,search:false,refreshstate:'current'});
	$uploadTodoList.jqGrid('setFrozenColumns');
	jqGridResize($uploadTodoList, $("#uploadGrid"));
});